.class public Lorg/microemu/app/util/MIDletResourceLoader;
.super Ljava/lang/Object;
.source "MIDletResourceLoader.java"


# static fields
.field private static final FQCN:Ljava/lang/String;

.field static class$org$microemu$Injected:Ljava/lang/Class;

.field public static classLoader:Ljava/lang/ClassLoader;

.field public static traceResourceLoading:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 51
    const/4 v0, 0x0

    sput-boolean v0, Lorg/microemu/app/util/MIDletResourceLoader;->traceResourceLoading:Z

    .line 58
    sget-object v0, Lorg/microemu/app/util/MIDletResourceLoader;->class$org$microemu$Injected:Ljava/lang/Class;

    if-nez v0, :cond_0

    const-string v0, "org.microemu.Injected"

    invoke-static {v0}, Lorg/microemu/app/util/MIDletResourceLoader;->class$(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v0

    sput-object v0, Lorg/microemu/app/util/MIDletResourceLoader;->class$org$microemu$Injected:Ljava/lang/Class;

    :goto_0
    invoke-virtual {v0}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lorg/microemu/app/util/MIDletResourceLoader;->FQCN:Ljava/lang/String;

    return-void

    :cond_0
    sget-object v0, Lorg/microemu/app/util/MIDletResourceLoader;->class$org$microemu$Injected:Ljava/lang/Class;

    goto :goto_0
.end method

.method public constructor <init>()V
    .locals 0

    .prologue
    .line 47
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method static class$(Ljava/lang/String;)Ljava/lang/Class;
    .locals 2
    .parameter "x0"

    .prologue
    .line 58
    :try_start_0
    invoke-static {p0}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
    :try_end_0
    .catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    return-object v1

    :catch_0
    move-exception v0

    .local v0, x1:Ljava/lang/ClassNotFoundException;
    new-instance v1, Ljava/lang/NoClassDefFoundError;

    invoke-direct {v1}, Ljava/lang/NoClassDefFoundError;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/NoClassDefFoundError;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;

    move-result-object v1

    throw v1
.end method

.method public static getResourceAsStream(Ljava/lang/Class;Ljava/lang/String;)Ljava/io/InputStream;
    .locals 4
    .parameter "origClass"
    .parameter "resourceName"

    .prologue
    .line 61
    sget-boolean v2, Lorg/microemu/app/util/MIDletResourceLoader;->traceResourceLoading:Z

    if-eqz v2, :cond_0

    .line 62
    const-string v2, "Loading MIDlet resource"

    invoke-static {v2, p1}, Lorg/microemu/log/Logger;->debug(Ljava/lang/String;Ljava/lang/String;)V

    .line 64
    :cond_0
    sget-object v2, Lorg/microemu/app/util/MIDletResourceLoader;->classLoader:Ljava/lang/ClassLoader;

    invoke-virtual {p0}, Ljava/lang/Class;->getClassLoader()Ljava/lang/ClassLoader;

    move-result-object v3

    if-eq v2, v3, :cond_1

    .line 66
    sget-object v2, Lorg/microemu/app/util/MIDletResourceLoader;->FQCN:Ljava/lang/String;

    invoke-static {v2}, Lorg/microemu/util/ThreadUtils;->getCallLocation(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 67
    .local v0, callLocation:Ljava/lang/String;
    if-eqz v0, :cond_1

    .line 68
    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    const-string v3, "attempt to load resource ["

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    const-string v3, "] using System ClasslLoader from "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lorg/microemu/log/Logger;->warn(Ljava/lang/String;)V

    .line 72
    .end local v0           #callLocation:Ljava/lang/String;
    :cond_1
    invoke-static {p0, p1}, Lorg/microemu/app/util/MIDletResourceLoader;->resolveName(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/String;

    move-result-object p1

    .line 74
    sget-object v2, Lorg/microemu/app/util/MIDletResourceLoader;->classLoader:Ljava/lang/ClassLoader;

    invoke-virtual {v2, p1}, Ljava/lang/ClassLoader;->getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;

    move-result-object v1

    .line 75
    .local v1, is:Ljava/io/InputStream;
    if-nez v1, :cond_2

    .line 76
    const-string v2, "Resource not found "

    invoke-static {v2, p1}, Lorg/microemu/log/Logger;->debug(Ljava/lang/String;Ljava/lang/String;)V

    .line 77
    const/4 v2, 0x0

    .line 79
    :goto_0
    return-object v2

    :cond_2
    new-instance v2, Lorg/microemu/app/util/MIDletResourceInputStream;

    invoke-direct {v2, v1}, Lorg/microemu/app/util/MIDletResourceInputStream;-><init>(Ljava/io/InputStream;)V

    goto :goto_0
.end method

.method private static resolveName(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/String;
    .locals 8
    .parameter "origClass"
    .parameter "name"

    .prologue
    const/16 v6, 0x2e

    const-string v7, "/"

    .line 84
    if-nez p1, :cond_0

    move-object v2, p1

    .line 99
    .end local p1
    .local v2, name:Ljava/lang/String;
    :goto_0
    return-object v2

    .line 87
    .end local v2           #name:Ljava/lang/String;
    .restart local p1
    :cond_0
    const-string v3, "/"

    invoke-virtual {p1, v7}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v3

    if-nez v3, :cond_3

    .line 88
    :goto_1
    invoke-virtual {p0}, Ljava/lang/Class;->isArray()Z

    move-result v3

    if-eqz v3, :cond_1

    .line 89
    invoke-virtual {p0}, Ljava/lang/Class;->getComponentType()Ljava/lang/Class;

    move-result-object p0

    goto :goto_1

    .line 91
    :cond_1
    invoke-virtual {p0}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v0

    .line 92
    .local v0, baseName:Ljava/lang/String;
    invoke-virtual {v0, v6}, Ljava/lang/String;->lastIndexOf(I)I

    move-result v1

    .line 93
    .local v1, index:I
    const/4 v3, -0x1

    if-eq v1, v3, :cond_2

    .line 94
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    const/4 v4, 0x0

    invoke-virtual {v0, v4, v1}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v4

    const/16 v5, 0x2f

    invoke-virtual {v4, v6, v5}, Ljava/lang/String;->replace(CC)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    const-string v4, "/"

    invoke-virtual {v3, v7}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object p1

    .end local v0           #baseName:Ljava/lang/String;
    .end local v1           #index:I
    .restart local p1
    :cond_2
    :goto_2
    move-object v2, p1

    .line 99
    .restart local v2       #name:Ljava/lang/String;
    goto :goto_0

    .line 97
    .end local v2           #name:Ljava/lang/String;
    :cond_3
    const/4 v3, 0x1

    invoke-virtual {p1, v3}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object p1

    .restart local p1
    goto :goto_2
.end method
